module Mobile
  class API < Grape::API
  	version 'v1', :using => :header, :vendor => 'yunmao'
    format :json

    helpers do
      def current_user
        @current_user ||= User.authorize!(env)
      end

      def authenticate!
        #error!('401 Unauthorized', 401) unless current_user
        unless current_user
      		logger.debug "authenticate fail with HTTP_X_USER_ACCESS_TOKEN #{env['HTTP_X_USER_ACCESS_TOKEN']} "
      		raise_401
    	end
      end
    end

    resource :movies do
      desc "Return a public timeline."
      get :categories do
         @categories = Category.movie.order(:updated_at).limit(20)
      end
  	end


  	protected

  	def http_authenticate
      authenticate_or_request_with_http_digest do |user_name, password|
        user_name == "foo" && password == "bar"
      end
      #warden.custom_failure! if performed?
    end
  end

end